package com.ptszyxx.popose.module.main.home;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;

import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.FragmentHomeRankBinding;
import com.ptszyxx.popose.module.main.home.vm.HomeRankVM;
import com.ysg.base.BaseFragment;
import com.ysg.base.BaseViewPagerAdapter;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YStatusBarUtil;

import java.util.ArrayList;

/**
 * 排行榜：女神榜，富豪榜，恩爱榜， 恩爱榜，家族榜， 魅力榜
 */
public class HomeRankFragment extends BaseFragment<FragmentHomeRankBinding, HomeRankVM> {

    public static HomeRankFragment getInstance() {
        return new HomeRankFragment();
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_home_rank;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public HomeRankVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(HomeRankVM.class);
    }

    @Override
    public void initStatusBar() {
        super.initStatusBar();
        YStatusBarUtil.setDarkTheme(this, binding.viewTitle);
    }

    @Override
    public void initView() {
        super.initView();
        ArrayList<Fragment> mFragments = new ArrayList<>();
        String[] mTitles = getResources().getStringArray(R.array.rank_list);
        for (String item: mTitles) {
            mFragments.add(new HomeRankTabFragment(item));
        }

        BaseViewPagerAdapter mAdapter = new BaseViewPagerAdapter(getChildFragmentManager(), mFragments);
        binding.viewpager.setAdapter(mAdapter);
        binding.tabLayout.setViewPager(binding.viewpager, mTitles);

    }
}
